package com.vvlive.caibao.smartcity.ui;

import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.LinearLayout;

import com.vvlive.caibao.smartcity.adapter.LifeOrderMealCanTAdapter;
import com.vvlive.caibao.smartcity.base.BaseActivity;
import com.vvlive.caibao.smartcity.bean.LifeOrderMealStoreBean;
import com.vvlive.caibao.smartcity.utils.MyRefreshListener;
import com.vvlive.caibao.smartcity.view.CommonActionBar;
import com.vvlive.caibao.smartcity.view.PullToRefreshLayout;
import com.vvlive.caibao.smartcity.view.PullableListView;
import com.vvlive.caibao.smartcity.view.SlideShowView;

import java.util.ArrayList;
import java.util.List;

import smartcity.vvlive.caibao.com.smartc.R;

/**
 * Created by lenovo on 2015/7/4.
 * 订餐主页
 */
public class LifeOrderMealActivity extends BaseActivity {
    //<图片轮播
    SlideShowView mSlideShowView;
    //图片轮播>

//    @BindView(id = R.id.zhaocanting,click = true)
    LinearLayout zhaocanting;
//    @BindView(id = R.id.jiaowaimai,click = true)
    LinearLayout jiaowaimai;
    //轮播图片
    int[]imgs1,imgs2;
    View view;
    PullableListView mPullableListView;
    List<LifeOrderMealStoreBean> mBeanList = new ArrayList<>();
    Intent mIntent;
    Class mClass;
    LinearLayout shaixuan;

    @Override
    protected int getContentViewRes() {
        return R.layout.refresh_list;
    }

    @Override
    public void initWidget() {
        super.initWidget();
        CommonActionBar actionbar = super.getCommonActionBar();
        actionbar.setTitle("订餐");
        mIntent = new Intent();
        mClass = LifeRestaurantActivity.class;
        view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.life_order_meal_index, null);
        shaixuan = (LinearLayout) view.findViewById(R.id.life_waimai_shaixuan);
        zhaocanting = (LinearLayout) view.findViewById(R.id.zhaocanting);
        jiaowaimai = (LinearLayout) view.findViewById(R.id.jiaowaimai);
        zhaocanting.setOnClickListener(this);
        jiaowaimai.setOnClickListener(this);
        //<图片轮播
        imgs1 = new int[]{R.mipmap.meishi_lb_1, R.mipmap.meishi_lb_2, R.mipmap.meishi_lb_3};
        imgs2 = new int[]{R.mipmap.meishi_lb_1, R.mipmap.meishi_lb_2, R.mipmap.meishi_lb_3};
        mSlideShowView = (SlideShowView) view.findViewById(R.id.slideShowView);
        mSlideShowView.start(imgs1);


        //图片轮播>

        ((PullToRefreshLayout) findViewById(R.id.pulltorefreshlayout))
                .setOnRefreshListener(new MyRefreshListener());
        mPullableListView = (PullableListView) findViewById(R.id.life_buttom_list);
        mPullableListView.addHeaderView(view);
        mPullableListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                mIntent.setClass(getApplicationContext().getApplicationContext(), mClass);
                mIntent.putExtra("dingcan", mBeanList.get(position-1));
                startActivity(mIntent);
            }
        });
        init();
        LifeOrderMealCanTAdapter orderMealListAdapter = new LifeOrderMealCanTAdapter(getApplication(),mBeanList);
        mPullableListView.setAdapter(orderMealListAdapter);
    }
    @Override
    public void widgetClick(View v) {
        super.widgetClick(v);
        switch (v.getId()) {
            case R.id.zhaocanting:
                //找餐厅
                refreshLayout(1);
                shaixuan.setVisibility(View.GONE);
                break;
            case R.id.jiaowaimai:
                refreshLayout(2);
                shaixuan.setVisibility(View.VISIBLE);
                //叫外卖
                break;
        }
    }

     /**
     * 刷新fragment
      * */
     private void refreshLayout(int ot){
        switch (ot){
            case 1://加载找餐厅的fragment
//                refreshImage(imgs1);
                mClass = LifeRestaurantActivity.class;
                init();
                LifeOrderMealCanTAdapter orderMealListAdapter = new LifeOrderMealCanTAdapter(getApplicationContext(),mBeanList);
                mPullableListView.setAdapter(orderMealListAdapter);

                break;
            case 2://加载叫外卖的fragment
//                refreshImage(imgs2);
                init();
                mClass = LifeEatOutListActivity.class;
                LifeOrderMealCanTAdapter orderMealListAdapter2 = new LifeOrderMealCanTAdapter(getApplicationContext(),mBeanList);
                mPullableListView.setAdapter(orderMealListAdapter2);
                break;
        }
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
    /**
     * 初始胡本地数据,测试用
     * */
    private void init(){
        mBeanList.add(new LifeOrderMealStoreBean(R.mipmap.dianpuming, "好粥道", 3, "25元起送", 0.0, 0.0, "",13.00));
        mBeanList.add(new LifeOrderMealStoreBean(R.mipmap.dianpuming, "便当x ", 4, "25元起送", 0.0, 0.0, "",13.00));
        mBeanList.add(new LifeOrderMealStoreBean(R.mipmap.dianpuming, "好运来", 1, "15元起送", 0.0, 0.0, "",13.00));
        mBeanList.add(new LifeOrderMealStoreBean(R.mipmap.dianpuming, "好运来", 1, "15元起送", 0.0, 0.0, "",13.00));
        mBeanList.add(new LifeOrderMealStoreBean(R.mipmap.dianpuming, "好粥道", 3, "25元起送", 0.0, 0.0, "",13.00));
        mBeanList.add(new LifeOrderMealStoreBean(R.mipmap.dianpuming, "好粥道", 3, "25元起送", 0.0, 0.0, "",13.00));
        mBeanList.add(new LifeOrderMealStoreBean(R.mipmap.dianpuming, "麦当劳", 5, "35元起送", 0.0, 0.0, "",13.00));
        mBeanList.add(new LifeOrderMealStoreBean(R.mipmap.dianpuming, "麦当劳", 5, "35元起送", 0.0, 0.0, "",13.00));
        mBeanList.add(new LifeOrderMealStoreBean(R.mipmap.dianpuming, "肯德基", 4, "45元起送", 0.0, 0.0, "",13.00));
        mBeanList.add(new LifeOrderMealStoreBean(R.mipmap.dianpuming, "肯德基", 4, "45元起送", 0.0, 0.0, "",13.00));
    }
}
